package commonfunctions;

import guiobjects.Observation;

import java.util.ArrayList;
import java.util.Collections;

public class GetStats 
{
	public static int[] print(ArrayList<Observation> obs, Matrix weights, Matrix tracks)
	{
		int[] toReturn = new int[2];
		ArrayList<ArrayList<Integer>> trackLists = new ArrayList<ArrayList<Integer>>();
		ArrayList<Integer> added = new ArrayList<Integer>();
		for (int i = 0; i < obs.size(); i++)
		{
			if (!added.contains(i))
			{
				ArrayList<Integer> thisTrack = new ArrayList<Integer>();
				ArrayList<Integer> toCheck = new ArrayList<Integer>();
				toCheck.add(i);
				while (toCheck.size() > 0)
				{
					int thisVal = toCheck.remove(0);
					if (!thisTrack.contains(thisVal))
					{
						thisTrack.add(thisVal);
						added.add(thisVal);
						boolean[] col = tracks.singelBooleanCol(thisVal);
						boolean[] row = tracks.singelBooleanRow(thisVal);
						for (int j = 0; j < col.length; j++)
						{
							if (col[j] || row[j])
								toCheck.add(j);
						}
					}
				}
				Collections.sort(thisTrack);
				trackLists.add(thisTrack);
			}
		}
		int numFalsePos = 0;
		int numFalseNeg = 0;
		for (int i = 0; i < trackLists.size(); i++)
		{
			ArrayList<Integer> thisTrack = trackLists.get(i);
			for (int j = 0; j < thisTrack.size() - 1; j++)
			{
				int lastNum = thisTrack.get(j);
				int nextNum = thisTrack.get(j + 1);
				if (obs.get(lastNum).id != obs.get(nextNum).id)
					numFalsePos++;
				for (int k = lastNum + 1; k < obs.size(); k++)
				{
					if (obs.get(k).id == obs.get(lastNum).id)
					{
						if (!thisTrack.contains(k))
							numFalseNeg++;
						break;
					}
				}
			}
			int lastNum = thisTrack.get(thisTrack.size() - 1);
			for (int j = lastNum + 1; j < obs.size(); j++)
			{
				if (obs.get(j).id == obs.get(lastNum).id && !thisTrack.contains(j))
				{
					numFalseNeg++;
					break;
				}
			}
		}
		toReturn[0] = numFalsePos;
		toReturn[1] = numFalseNeg;
		return toReturn;
	}
}
